﻿/**************************************************************************
创建日期:	2019/7/22 11:27:07     
作	  者:	张存
邮 	  箱:	zhangcunliang@126.com
创建时间:	
Copyright (c)  ZhCun.cn

描	述：
记	录：
***************************************************************************/
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
using ZhCun.DbCore.Entitys;
using ZhCun.WebCommon.AL;
using ZhCun.WebCommon.ApiModels;
using ZhCun.WebCommon.ViewModels;

namespace ZhCun.WebCommon.WebApi
{
    public class ApiCRUDBaseController<TAL, TListArg, TSaveModel> : ApiCRUDBaseController<TAL, TListArg, TSaveModel, TSaveModel>
        where TListArg : ArgGetList, new()
        where TSaveModel : EntityBase, new()        
        where TAL : ALCRUDBase<TListArg, TSaveModel>, new()
    { }

    public class ApiCRUDBaseController<TAL, TListArg, TSaveModel, TListModel> : ApiAuthorizeController<TAL>
        where TListArg : ArgGetList, new()
        where TSaveModel : class, new()
        where TListModel : EntityBase, new()        
        where TAL : ALCRUD<TListArg, TSaveModel, TListModel>, new()
    {
        /// <summary>
        /// 获取列表
        /// </summary>
        [HttpPost]
        public virtual ApiResultArray<TListModel> GetList(TListArg arg)
        {
            List<TListModel> rList = ALObj.GetList(arg, out int total);
            return CreateArrayResult<TListModel>(rList, total);
        }
        /// <summary>
        /// 新增
        /// </summary>
        [HttpPost]
        public virtual ApiResult Add(TSaveModel arg)
        {
            bool r = ALObj.Add(arg, out string msg);
            return CreateResult(r, msg);
        }
        /// <summary>
        /// 更新
        /// </summary>
        [HttpPost]
        public virtual ApiResult Update(TSaveModel arg)
        {
            bool r = ALObj.Update(arg, out string msg);
            return CreateResult(r, msg);
        }
        /// <summary>
        /// 删除
        /// </summary>
        [HttpPost]
        public virtual ApiResult Del(ArgId arg)
        {
            bool r = ALObj.Del(arg.Id, out string msg);
            return CreateResult(r, msg);
        }
    }
}